# -- coding: utf-8 --

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select

if __name__ == '__main__':

    driver = webdriver.Firefox()
    driver.implicitly_wait(5)
    driver.maximize_window()

    # 登录操作
    driver.get('http://192.168.44.128:8080/WoniuBoss4.0')
    driver.find_element(By.NAME, 'userName').send_keys('WNCD000')
    driver.find_element(By.NAME, 'userPass').send_keys('woniu123')
    driver.find_element(By.CSS_SELECTOR, '.btn').click()

    driver.get('http://192.168.44.128:8080/WoniuBoss4.0/borrow')
    driver.find_element(By.CSS_SELECTOR, 'div.pull-right:nth-child(7) > button:nth-child(1)').click()
    driver.find_element(By.NAME, 'AssCode').send_keys('93987654326')

    owner_type = driver.find_element(By.CSS_SELECTOR,  '#addBor-form > div:nth-child(1) > '
                                                       'div:nth-child(1) > div:nth-child(1) > div:nth-child(2) > select:nth-child(2)')
    size = len(Select(owner_type).options)
    import random
    random_index = random.randint(1, size-1)
    Select(owner_type).select_by_index(random_index)

    driver.find_element(By.NAME, 'borrower').send_keys('孔银花')
    import time
    time.sleep(2)
    driver.find_element(By.CSS_SELECTOR, '.dropdown-item').click()
    note = driver.find_element(By.CSS_SELECTOR, '#addBor-form > div:nth-child(1) > '
                                                'div:nth-child(1) > div:nth-child(2) > div:nth-child(2) > input:nth-child(2)')
    note.send_keys('123')
    driver.find_element(By.ID, 'addAssBtn').click()
    # 弹窗中的确认元素：css  .bootbox > div:nth-child(1) > div:nth-child(1) > div:nth-child(3) > button:nth-child(1)
    # 列表信息：css .pagination-info

    driver.find_element(By.CSS_SELECTOR, '#borrow-table > tbody:nth-child(2) > tr:nth-child(1) > td:nth-child(10) > button:nth-child(2)').click()
    time.sleep(2)
    driver.find_element(By.CSS_SELECTOR, 'button.btn-primary:nth-child(2)').click()